package priv.yiyuan.example.design.pay01;

import java.util.HashMap;
import java.util.Map;

/**
 * 支付上下文
 * <p>
 * 策略模式
 *
 * @author YiYuan
 * @data 2025/8/8
 * @apoNote
 */
public class PaymentContext {

    private PaymentStrategy paymentStrategy;

    private static Map<String, PaymentStrategy> strategies = new HashMap<>();

    public PaymentContext(PaymentStrategy paymentStrategy) {
        this.paymentStrategy = paymentStrategy;
    }

    public static void registerStrategy(String name, PaymentStrategy strategy) {
        strategies.put(name, strategy);
    }

    public static PaymentStrategy getStrategy(String name) {
        return strategies.get(name);
    }

    public void executePayment(double amount) {
        paymentStrategy.pay(amount);
    }
}
